<template>
  <div>
    <a-drawer :title="$t('user.verification-code.required111566110577257')" :width="550" :visible.sync="visible"
      :body-style="{ 'padding-top': '0px', paddingBottom: '80px' }" @close="close">
      <a-form-item>
        <a-button type="primary" icon="plus" @click="create()">{{
        $t('user.verification-code.required1115661106') }}</a-button>
        </a-form-item>
      <!-- 主列表 -->
      <a-table ref="table" size="middle" class="h-full overflow-x-auto" :dataSource="listData" :pagination="true"
        @change="tableChange" :loading="listLoading" :rowKey="record => record.Id">
        <a-table-column key="RpaViewName" data-index="RpaViewName">
          <span slot="title" class="min-w-90p">{{ $t('user.verification-code.required1115661105714') }}</span>
        </a-table-column>
        <a-table-column key="RpaViewCreatetime" data-index="RpaViewCreatetime">
          <span slot="title" class="min-w-90p">{{ $t('user.verification-code.required111566131') }}</span>
        </a-table-column>
        <a-table-column key="action" :title="$t('app.setting.othersettings')">
          <template slot-scope="text, record">
            <span>
              <!-- 删除按钮 -->
              <a-popconfirm :title="$t('user.verification-code.required111566110577225')"
                :ok-text="$t('user.verification-code.required1166')" :cancel-text="$t('user.email.required11')"
                @confirm="() => del(record)">
                <a-button type="link" size="small">{{ $t('app.setting.copy') }}</a-button>
              </a-popconfirm>
            </span>
          </template>
        </a-table-column>
      </a-table>
    </a-drawer>
    <PermissionsDrow ref="PermissionsDrow" :rpaId='rpaId' @succeed="getList"></PermissionsDrow>
  </div>
</template>
    
<script>
import { rpaPermissionDelete, rpaPermissionList } from '@/api/rpa/form'
import PermissionsDrow from './permissionsDrow.vue'
const columns = [
  {
    title: '姓名',
    className: 'min-w-90p',
    dataIndex: 'DpiaViewName',
    align: 'center',
  },
  {
    title: '创建时间',
    className: 'min-w-90p',
    dataIndex: 'DpiaViewCreatetime',
    align: 'center',
  },
  {
    title: '操作',
    width: '150px',
    dataIndex: '',
    align: 'center',
    scopedSlots: { customRender: 'action' },
  },
]

export default {
  components: {
    PermissionsDrow
  },
  data() {
    return {
      columns: columns,
      /**table数据 */
      listData: [],
      // table的loading 状态
      listLoading: false,
      // 下面这些都是通用的
      form: this.$form.createForm(this),
      visible: false,
      loading: false,
      // 分页参数
      pagination: {
        current: 1, //当前页
        pageSize: 10, //每页条数
        total: 0, //总条数
        showQuickJumper: true,
        hideOnSinglePage: true,
        showTotal: (total) => this.$t('user.verification-code.required111566110577216', { total }, 'user.verification-code.required111566110577217'),
      },
      rpaId: null
    }
  },
  methods: {
    async open(data = {}) {
      console.log('1');
      console.log('data', data);
      this.rpaId = data.Id
      this.visible = true
      this.pagination.current = 1
      this.getList()
    },
    async getList() {
      this.listLoading = true
      const { current, pageSize } = this.pagination
      console.log('pageSize', pageSize);
      try {
        // 调用查询列表
        const { data: data1 } = await rpaPermissionList({
          ...{ page: current, pageSize: pageSize },
          RpaQid: this.rpaId,
        })
        console.log('data-----', data1);
        this.listData = data1
        // 解构赋值
        // const { Page, PageSize, Total, Lists } = data
        // 给table赋值
        // this.listData = Lists || []
        // 给分页数据赋值
        // this.pagination = {
        //   current: Page,
        //   pageSize: PageSize,
        //   total: Total,
        // }
      } catch (error) {
        // 报错信息
        this.$message.error(error)
        console.log(error);
      } finally {
        // 不管成功失败都会执行
        this.listLoading = false
      }
    },

    // 分页事件 直接复制使用 通用的
    tableChange(pagination) {
      this.pagination = pagination
      this.getList()
    },

    create() {
      this.$refs.PermissionsDrow.open()
    },
    async del(record) {
      console.log('record', record);
      try {
        // 传过来的id直接请求删除api
        const { data } = await rpaPermissionDelete({ RpaQid: record.RpaQid, Ids: record.RpaViewId })
        console.log('data', data);
        this.$message.success(this.$t('user.verification-code.required111566110577133'))
        // 重新初始化列表刷新数据
        this.getList()
      } catch (error) {
        this.$message.error(error)
      } finally {
      }
    },
    // 关闭 通用的 
    close() {
      // 修改侧边栏状态
      this.visible = false
      // 清空form的值
      this.form.resetFields()
    },
  }
}
</script>
    
<style></style>